﻿using System.Runtime.CompilerServices;
using SoftFloat;

namespace BEPUutilities
{
    public partial struct NVector3
    {
        public static NVector3 One = new NVector3(1, 1, 1);

        public NVector3 Normalized => Normalize(this);

        //[MethodImpl(MethodImplOptions.AggressiveInlining)]
        //public static NVector3 Normalize(NVector3 value)
        //{
        //    sfloat num = Magnitude(value);
        //    if (num > 1E-05f)
        //    {
        //        return value / num;
        //    }

        //    return Zero;
        //}

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static sfloat Magnitude(NVector3 vector)
        {
            return libm.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static sfloat SqrMagnitude(NVector3 vector)
        {
            return vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z;
        }

        //[MethodImpl(MethodImplOptions.AggressiveInlining)]
        //public static NVector3 operator /(NVector3 a, sfloat d)
        //{
        //    return new NVector3(a.X / d, a.Y / d, a.Z / d);
        //}

        //[MethodImpl(MethodImplOptions.AggressiveInlining)]
        //public static sfloat Distance(NVector3 a, NVector3 b)
        //{
        //    sfloat num = a.X - b.X;
        //    sfloat num2 = a.Y - b.Y;
        //    sfloat num3 = a.Z - b.Z;
        //    return libm.Sqrt(num * num + num2 * num2 + num3 * num3);
        //}

#if UNITY
        public static bool operator ==(UnityEngine.Vector3 lhs, NVector3 rhs)
        {
            return ((NVector3)lhs - rhs).Length() < (float)9.9999994E-11f;
        }

        public static bool operator !=(UnityEngine.Vector3 lhs, NVector3 rhs)
        {
            return !(lhs == rhs);
        }

        public static implicit operator UnityEngine.Vector3(NVector3 v)
        {
            return new UnityEngine.Vector3(v.X, v.Y, v.Z);
        }

        public static implicit operator NVector3(UnityEngine.Vector3 v)
        {
            return new NVector3(v.x, v.y, v.z);
        }
#endif
    }
}